package com.sunny.blog.controller;

import com.sunny.blog.common.entity.Response;
import com.sunny.blog.common.entity.ResponseResult;
import com.sunny.blog.common.entity.ResultCode;
import com.sunny.blog.pojo.BlogTagBean;
import com.sunny.blog.pojo.BlogTypeBean;
import com.sunny.blog.service.BlogInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: BlogPostManController
 * @Description: 通过postMan操作，不想写页面，避免登录操作
 * @Author: sunt
 * @Date: 2020/4/29 11:15
 * @Version 1.0
 **/
@RestController
@RequestMapping("postMan")
public class BlogPostManController {

    @Autowired
    private BlogInfoService blogInfoService;
    /**
     * 新增分类
     * @return
     */
    @PostMapping("addType")
    public ResponseResult<String> insertBlogType(@RequestBody BlogTypeBean typeBean) {
        try {
            blogInfoService.insertBlogType(typeBean);
            return Response.makeRsp(ResultCode.SUCCESS.code,"分类添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Response.makeErrRsp();
        }
    }

    /**
     * 新增标签
     * @param tagBean
     * @return
     */
    @PostMapping("addTag")
    public ResponseResult<String> insertBlogTag(@RequestBody BlogTagBean tagBean) {
        try {
            blogInfoService.insertBlogTag(tagBean);
            return Response.makeRsp(ResultCode.SUCCESS.code,"标签添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Response.makeErrRsp();
        }
    }
}
